<?php
/**
 * Created by PhpStorm.
 * User: zhongyb
 * Date: 2016/6/6
 * Time: 21:01
 */
namespace common\repositories\common;

use common\repositories\BaseRepository;
use common\entities\common\MyscrmOperlogEntity;
use common\support\StringHelper;
use Yii;

class MyscrmOperlogRepository extends BaseRepository {


    public function deleteByOrganizationId($organizationId)
    {
        return MyscrmOperlogEntity::deleteAll([
            'OrganizationId' => $organizationId
        ]);
    }

    /**
     * 添加记录
     * @param $orgId
     * @param $reason
     * @param $type
     * @return bool
     */
    public function addOperLog($orgId, $reason, $type)
    {
        $entity = new MyscrmOperlogEntity();
        $entity->isNewRecord = true;
        $entity->Id = StringHelper::uuid();
        $entity->OrganizationId = $orgId;
        $entity->Reason = $reason;
        $entity->Type = $type;
        $entity->VersionNumber = 'System.B';
        $entity->ModifiedOn = date('y-m-d H:i:s');

        if(!$entity->save()){
            return false;
        }else{
            return true;
        }
    }

}